package com.blue.base.oauth.server.config.endpoint;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录认证错误重定向配置
 *
 * @author liulei
 * @version 1.0
 */
@Slf4j
public class ErrorEntryPointRedirect implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
            throws IOException, ServletException {
        log.info("登录身份未认证，重定向配置:{}", e.toString());
        // 如果想做前后台分离，这边可以写http://xxx/yy/zz
        response.sendRedirect("/login");
    }
}
